﻿<sdk:Page x:Class="MoneyBook.Views.LoginView" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
           xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
           xmlns:li="clr-namespace:MoneyBook.Interactivity"
           xmlns:lv="clr-namespace:MoneyBook.Views"
           xmlns:ld="clr-namespace:MoneyBook.Windows.Data"
           xmlns:lm="clr-namespace:MoneyBook.Windows.Markup"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
           d:DesignWidth="640" d:DesignHeight="480"
           Title="LoginView Page"
           x:Name="Self">
    <sdk:Page.Resources>
        <Style TargetType="TextBox" BasedOn="{StaticResource InputControlStyle}">
            <Setter Property="Height" Value="28" />
            <Setter Property="Width" Value="160" />
        </Style>
        <Style TargetType="PasswordBox" BasedOn="{StaticResource InputControlStyle}">
            <Setter Property="Height" Value="28" />
            <Setter Property="Width" Value="160" />
        </Style>
    </sdk:Page.Resources>
    
    <sdk:Page.DataContext>
        <lv:LoginViewModel />
    </sdk:Page.DataContext>
    <Grid x:Name="LayoutRoot">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <li:InvokeMethodAction TargetObject="{Binding DataContext, ElementName=Self}" MethodName="ValidateAllProperties">
                    <li:Parameter Value="True" />
                </li:InvokeMethodAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <sdk:ValidationSummary Grid.Row="0" Width="400" HorizontalAlignment="Left" />

        <Grid Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">
            <i:Interaction.Behaviors>
                <li:DefaultButtonBehavior TargetButton="{Binding ElementName=LoginButton}" />
                <li:FocusBehavior Target="{Binding ElementName=MemberNameTextBox}" />
            </i:Interaction.Behaviors>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <sdk:Label Target="{Binding ElementName=MemberNameTextBox}" />
            <TextBox Grid.Column="1" x:Name="MemberNameTextBox" 
                     Text="{Binding MemberName, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=Explicit}" 
                     ld:BindingHelper.UpdateSourceTrigger="{lm:UpdateSourceTrigger TargetProperty=Text, TargetEvent=TextChanged}"/>

            <sdk:Label Grid.Row="1" Target="{Binding ElementName=PasswordTextBox}" />
            <PasswordBox Grid.Row="1" Grid.Column="1" x:Name="PasswordTextBox"
                         Password="{Binding Password, Mode=TwoWay, ValidatesOnExceptions=True,NotifyOnValidationError=True, UpdateSourceTrigger=Explicit}"
                         ld:BindingHelper.UpdateSourceTrigger="{lm:UpdateSourceTrigger TargetProperty=Password, TargetEvent=PasswordChanged}" />

            <Button Content="{Binding LoginButton,Source={StaticResource Strings}}" x:Name="LoginButton"  
                    Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" 
                    IsEnabled="{Binding CanLogin}">
                <!--IsEnabled="{Binding HasErrors,Converter={StaticResource BooleanInverter}}">-->
                <!--IsEnabled="{Binding AuthService.IsBusy,Converter={StaticResource BooleanInverter}}"-->
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                    	<i:Interaction.Behaviors>
                    		<ei:ConditionBehavior>
                    			<ei:ConditionalExpression>
                                    <ei:ComparisonCondition LeftOperand="{Binding DataContext.CanLogin, ElementName=Self}"
                                                            RightOperand="true" />
                    			</ei:ConditionalExpression>
                    		</ei:ConditionBehavior>
                    	</i:Interaction.Behaviors>
                        <li:InvokeMethodAction TargetObject="{Binding DataContext, ElementName=Self}" MethodName="Login"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </Grid>
    </Grid>
</sdk:Page>